﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Runtime.Serialization.Formatters.Binary;

namespace AktionServer
{
    class Program
    {
        private const int PORT = 12345;

        static void Main(string[] args)
        {
            IPEndPoint port;
            Socket klientSocket;
            Thread traadHaandterKlienter;
            
            port = new IPEndPoint(IPAddress.Any, PORT);

            Socket serverLytter = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            serverLytter.Bind(port);
            serverLytter.Listen(10);

            Produkt produkt = new Produkt();

            Monitor monitor = new Monitor();

            while (true)
            {
                Console.WriteLine("Venter på klient...");

                klientSocket = serverLytter.Accept();
                Console.WriteLine("Klient logget på");

                //serverTraad = new ServerTraade(serverLytter, monitor);
                Skeleton skeleton = new Skeleton(klientSocket, produkt, monitor);
                traadHaandterKlienter = new Thread(new ThreadStart(skeleton.HaandterKlient));
                traadHaandterKlienter.Start();

                traadHaandterKlienter = new Thread(new ThreadStart(skeleton.UdfoerBud));
                traadHaandterKlienter.Start();

                //ThreadStart traadMetodeBroadcast = new ThreadStart (skeleton.HaandterKlient);
                //Thread traadBroadcast = new Thread(traadMetodeBroadcast);
                //traadBroadcast.Start();

            }
        }
    }
}
